/*   1:    */ package org.intellij.images.editor.impl;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.*;
import org.intellij.images.editor.ImageDocument;
import org.intellij.images.editor.ImageEditor;
import org.intellij.images.editor.ImageZoomModel;
import org.intellij.images.fileTypes.ImageFileTypeManager;
import org.intellij.images.options.*;
import org.intellij.images.ui.ImageComponent;
import org.intellij.images.vfs.IfsUtil;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */
/*  25:    */
/*  26:    */
/*  27:    */
/*  28:    */ 
/*  29:    */ final class ImageEditorImpl
/*  30:    */   extends VirtualFileAdapter
/*  31:    */   implements ImageEditor
/*  32:    */ {
/*  33: 43 */   private final PropertyChangeListener a = new OptionsChangeListener(null);
/*  34:    */   private final Project b;
/*  35:    */   private final VirtualFile c;
/*  36:    */   private final ImageEditorUI d;
/*  37:    */   private boolean e;
/*  38:    */   
/*  39:    */   ImageEditorImpl(@NotNull Project paramProject, @NotNull VirtualFile paramVirtualFile)
/*  40:    */   {
/*  41: 50 */     this.b = paramProject;
/*  42: 51 */     this.c = paramVirtualFile;
/*  43:    */     
/*  44:    */ 
/*  45: 54 */     Options localOptions = OptionsManager.getInstance().getOptions();
/*  46: 55 */     this.d = new ImageEditorUI(this, localOptions.getEditorOptions());
/*  47: 56 */     localOptions.addPropertyChangeListener(this.a);
/*  48:    */     
/*  49: 58 */     VirtualFileManager.getInstance().addVirtualFileListener(this);
/*  50:    */     
/*  51: 60 */     a(paramVirtualFile);
/*  52:    */   }
/*  53:    */   
/*  54:    */   private void a(VirtualFile paramVirtualFile)
/*  55:    */   {
/*  56: 64 */     ImageDocument localImageDocument = this.d.getImageComponent().getDocument();
/*  57:    */     try
/*  58:    */     {
/*  59: 66 */       BufferedImage localBufferedImage1 = localImageDocument.getValue();
/*  60: 67 */       BufferedImage localBufferedImage2 = IfsUtil.getImage(paramVirtualFile);
/*  61: 68 */       localImageDocument.setValue(localBufferedImage2);
/*  62: 69 */       localImageDocument.setFormat(IfsUtil.getFormat(paramVirtualFile));
/*  63: 70 */       ImageZoomModel localImageZoomModel = getZoomModel();
/*  64: 71 */       if ((localBufferedImage2 != null) && ((localBufferedImage1 == null) || (!localImageZoomModel.isZoomLevelChanged())))
/*  65:    */       {
/*  66: 73 */         Options localOptions = OptionsManager.getInstance().getOptions();
/*  67: 74 */         ZoomOptions localZoomOptions = localOptions.getEditorOptions().getZoomOptions();
/*  68:    */         
/*  69: 76 */         localImageZoomModel.setZoomFactor(1.0D);
/*  70: 78 */         if (localZoomOptions.isSmartZooming())
/*  71:    */         {
/*  72: 79 */           Dimension localDimension = localZoomOptions.getPrefferedSize();
/*  73: 80 */           if ((localDimension.width > localBufferedImage2.getWidth()) && (localDimension.height > localBufferedImage2.getHeight()))
/*  74:    */           {
/*  75: 84 */             double d1 = (localDimension.getWidth() / localBufferedImage2.getWidth() + localDimension.getHeight() / localBufferedImage2.getHeight()) / 2.0D;
/*  76: 85 */             localImageZoomModel.setZoomFactor(Math.ceil(d1));
/*  77:    */           }
/*  78:    */         }
/*  79:    */       }
/*  80:    */     }
/*  81:    */     catch (Exception localException)
/*  82:    */     {
/*  83: 91 */       localImageDocument.setValue(null);
/*  84:    */     }
/*  85:    */   }
/*  86:    */   
/*  87:    */   public boolean isValid()
/*  88:    */   {
/*  89: 96 */     ImageDocument localImageDocument = this.d.getImageComponent().getDocument();
/*  90: 97 */     return localImageDocument.getValue() != null;
/*  91:    */   }
/*  92:    */   
/*  93:    */   public JComponent getComponent()
/*  94:    */   {
/*  95:101 */     return this.d;
/*  96:    */   }
/*  97:    */   
/*  98:    */   public JComponent getContentComponent()
/*  99:    */   {
/* 100:105 */     return this.d.getImageComponent();
/* 101:    */   }
/* 102:    */   
/* 103:    */   @NotNull
/* 104:    */   public VirtualFile getFile()
/* 105:    */   {
/* 106:110 */     VirtualFile tmp4_1 = this.c;
/* 107:110 */     if (tmp4_1 == null) {
/* 108:110 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/images/editor/impl/ImageEditorImpl", "getFile" }));
/* 109:    */     }
/* 110:110 */     return tmp4_1;
/* 111:    */   }
/* 112:    */   
/* 113:    */   @NotNull
/* 114:    */   public Project getProject()
/* 115:    */   {
/* 116:115 */     Project tmp4_1 = this.b;
/* 117:115 */     if (tmp4_1 == null) {
/* 118:115 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/images/editor/impl/ImageEditorImpl", "getProject" }));
/* 119:    */     }
/* 120:115 */     return tmp4_1;
/* 121:    */   }
/* 122:    */   
/* 123:    */   public ImageDocument getDocument()
/* 124:    */   {
/* 125:119 */     return this.d.getImageComponent().getDocument();
/* 126:    */   }
/* 127:    */   
/* 128:    */   public void setTransparencyChessboardVisible(boolean paramBoolean)
/* 129:    */   {
/* 130:123 */     this.d.getImageComponent().setTransparencyChessboardVisible(paramBoolean);
/* 131:124 */     this.d.repaint();
/* 132:    */   }
/* 133:    */   
/* 134:    */   public boolean isTransparencyChessboardVisible()
/* 135:    */   {
/* 136:128 */     return this.d.getImageComponent().isTransparencyChessboardVisible();
/* 137:    */   }
/* 138:    */   
/* 139:    */   public boolean isEnabledForActionPlace(String paramString)
/* 140:    */   {
/* 141:133 */     return !"Images.Thumbnails".equals(paramString);
/* 142:    */   }
/* 143:    */   
/* 144:    */   public void setGridVisible(boolean paramBoolean)
/* 145:    */   {
/* 146:137 */     this.d.getImageComponent().setGridVisible(paramBoolean);
/* 147:138 */     this.d.repaint();
/* 148:    */   }
/* 149:    */   
/* 150:    */   public boolean isGridVisible()
/* 151:    */   {
/* 152:142 */     return this.d.getImageComponent().isGridVisible();
/* 153:    */   }
/* 154:    */   
/* 155:    */   public boolean isDisposed()
/* 156:    */   {
/* 157:146 */     return this.e;
/* 158:    */   }
/* 159:    */   
/* 160:    */   public ImageZoomModel getZoomModel()
/* 161:    */   {
/* 162:150 */     return this.d.getZoomModel();
/* 163:    */   }
/* 164:    */   
/* 165:    */   public void dispose()
/* 166:    */   {
/* 167:154 */     Options localOptions = OptionsManager.getInstance().getOptions();
/* 168:155 */     localOptions.removePropertyChangeListener(this.a);
/* 169:156 */     this.d.dispose();
/* 170:157 */     VirtualFileManager.getInstance().removeVirtualFileListener(this);
/* 171:158 */     this.e = true;
/* 172:    */   }
/* 173:    */   
/* 174:    */   public void propertyChanged(@NotNull VirtualFilePropertyEvent paramVirtualFilePropertyEvent)
/* 175:    */   {
/* 176:162 */     if (paramVirtualFilePropertyEvent == null) {
/* 177:162 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/images/editor/impl/ImageEditorImpl", "propertyChanged" }));
/* 178:    */     }
/* 179:162 */     super.propertyChanged(paramVirtualFilePropertyEvent);
/* 180:163 */     if (this.c.equals(paramVirtualFilePropertyEvent.getFile())) {
/* 181:165 */       this.c.refresh(true, false, new Runnable()
/* 182:    */       {
/* 183:    */         public void run()
/* 184:    */         {
/* 185:167 */           if (ImageFileTypeManager.getInstance().isImage(ImageEditorImpl.this.c))
/* 186:    */           {
/* 187:168 */             ImageEditorImpl.this.a(ImageEditorImpl.this.c);
/* 188:    */           }
/* 189:    */           else
/* 190:    */           {
/* 191:170 */             ImageEditorImpl.this.a(null);
/* 192:    */             
/* 193:172 */             FileEditorManager localFileEditorManager = FileEditorManager.getInstance(ImageEditorImpl.this.b);
/* 194:173 */             localFileEditorManager.closeFile(ImageEditorImpl.this.c);
/* 195:    */           }
/* 196:    */         }
/* 197:    */       });
/* 198:    */     }
/* 199:    */   }
/* 200:    */   
/* 201:    */   public void contentsChanged(@NotNull VirtualFileEvent paramVirtualFileEvent)
/* 202:    */   {
/* 203:181 */     if (paramVirtualFileEvent == null) {
/* 204:181 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/images/editor/impl/ImageEditorImpl", "contentsChanged" }));
/* 205:    */     }
/* 206:181 */     super.contentsChanged(paramVirtualFileEvent);
/* 207:182 */     if (this.c.equals(paramVirtualFileEvent.getFile())) {
/* 208:184 */       this.c.refresh(true, false, new Runnable()
/* 209:    */       {
/* 210:    */         public void run()
/* 211:    */         {
/* 212:186 */           ImageEditorImpl.this.a(ImageEditorImpl.this.c);
/* 213:    */         }
/* 214:    */       });
/* 215:    */     }
/* 216:    */   }
/* 217:    */   
/* 218:    */   private class OptionsChangeListener
/* 219:    */     implements PropertyChangeListener
/* 220:    */   {
/* 221:    */     private OptionsChangeListener() {}
/* 222:    */     
/* 223:    */     public void propertyChange(PropertyChangeEvent paramPropertyChangeEvent)
/* 224:    */     {
/* 225:194 */       Options localOptions = (Options)paramPropertyChangeEvent.getSource();
/* 226:195 */       EditorOptions localEditorOptions = localOptions.getEditorOptions();
/* 227:196 */       TransparencyChessboardOptions localTransparencyChessboardOptions = localEditorOptions.getTransparencyChessboardOptions();
/* 228:197 */       GridOptions localGridOptions = localEditorOptions.getGridOptions();
/* 229:    */       
/* 230:199 */       ImageComponent localImageComponent = ImageEditorImpl.this.d.getImageComponent();
/* 231:200 */       localImageComponent.setTransparencyChessboardCellSize(localTransparencyChessboardOptions.getCellSize());
/* 232:201 */       localImageComponent.setTransparencyChessboardWhiteColor(localTransparencyChessboardOptions.getWhiteColor());
/* 233:202 */       localImageComponent.setTransparencyChessboardBlankColor(localTransparencyChessboardOptions.getBlackColor());
/* 234:203 */       localImageComponent.setGridLineZoomFactor(localGridOptions.getLineZoomFactor());
/* 235:204 */       localImageComponent.setGridLineSpan(localGridOptions.getLineSpan());
/* 236:205 */       localImageComponent.setGridLineColor(localGridOptions.getLineColor());
/* 237:    */     }
/* 238:    */   }
/* 239:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.images.editor.impl.ImageEditorImpl

 * JD-Core Version:    0.7.0.1

 */